/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package neuronalenetzeelearning.view.gui;

import neuronalenetzeelearning.model.Edge;
import neuronalenetzeelearning.view.IController;
import neuronalenetzeelearning.model.Graph;
import neuronalenetzeelearning.view.IView;
import prefuse.data.Node;

/**
 *
 * @author svenmaster
 */
public class Controller implements IController {

    //graph bekommt
    private neuronalenetzeelearning.model.Graph graph;
    private GUI view;

    //controller bekommt graph und gui und leitet daten an die weiter
    public Controller(Graph graph, GUI gui) {
        this.graph = graph;
        this.view = gui;
        graph.setController(this);
        view.setController(this);
    }

    @Override
    public void addNode(neuronalenetzeelearning.model.Node node){
        //both adding node to the graph (datamodel) and the viz (prefuse-graph)
        graph.addNode(node);
        view.addNode(node);
        //repaint everything, doing the update-action
        view.getGraphViz().recalculatePositions();
        updateView();
    }

    //sorgt für die umsetzung der Klicks in die visualisierung
    @Override
    public void updateView(){
        view.repaint();
        view.getGraphVizPanel().repaint();
        view.getGraphViz().getDisplay().repaint();
        view.getGraphViz().getVisualization().run("update");
        view.getMatrixComponent().updateMatrix(getGraph().getWeightMatrix());
    }

    public void changeNodeName(Node node, String newName){
        node.set("name",newName);
        updateView();
    }

    public Graph getGraph() {
        return graph;
    }

    public void setGraph(Graph graph) {
        this.graph = graph;
    }

    public GUI getView() {
        return view;
    }


    public void setView(IView view) {
        this.view = (GUI) view;
    }

    @Override
    public void addEdge(neuronalenetzeelearning.model.Node from, neuronalenetzeelearning.model.Node to) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteEdge(Edge edge) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteNode(neuronalenetzeelearning.model.Node node) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
